Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next |

Creating and Disposing of Color Tables

You use a color table, which is defined by a data structure of type ColorTable , to specify colors in the form of RGBColor records. You can create and store color tables in 'clut' resources. To retrieve a color table stored in a 'clut' resource, you can use the GetCTable function. To dispose of the handle allocated for a color table, you use the DisposeCTable procedure.

The Palette Manager, described in the chapter "Palette Manager" in Inside Macintosh: Advanced Color Imaging , has additional routines that enable you to copy colors between palettes and color tables and to restore the default colors to a CLUT belonging to a graphics device.

The Color Manager, described in the chapter "Color Manager" in Inside Macintosh: Advanced Color Imaging , contains low-level routines for directly manipulating the fields of the CLUT on a graphics device; most applications do not need to use those routines.

GetCTable

To get a color table stored in a 'clut' resource, use the GetCTable function.

FUNCTION GetCTable (ctID: Integer): CTabHandle;
ctID
The resource ID of a 'clut' resource.

DESCRIPTION

For the color table defined in the 'clut' resource that you specify in the ctID parameter, the GetCTable function returns a handle to a ColorTable record. If the 'clut' resource with that ID is not found, GetCTable returns NIL .

If you place this handle in the pmTable field of a PixMap record, you should first use the DisposeCTable procedure to dispose of the handle already there.

If you modify a ColorTable record, you should invalidate it by changing its ctSeed field. An easy way to do this is with the CTabChanged procedure, described on CTabChanged .

The GetCTable function recognizes a number of standard 'clut' resource IDs. You can obtain the default grayscale color table for a given pixel depth by calling GetCTable , adding 32 (decimal) to the pixel depth, and passing this value in the ctID parameter, as shown in Table 4-5 .

Table 5 The default color tables for grayscale graphics devices

Pixel depth

Resource ID

Color table composition

1

33

Black, white

2

34

Black, 33% gray, 66% gray, white

4

36

Black, 14 shades of gray, white

8

40

Black, 254 shades of gray, white

For full color, you can obtain the default color tables by adding 64 to the pixel depth and passing this in the ctID parameter, as shown in Table 4-6 . These default color tables are illustrated in Plate 1 at the front of this book.

Table 6 The default color tables for color graphics devices

Pixel depth

Resource ID

Color table composition

2

66

Black, 50% gray, highlight color, white

4

68

Black, 14 colors including the highlight color, white

8

72

Black, 254 colors including the highlight color, white

SPECIAL CONSIDERATIONS

The GetCTable function may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.

SEE ALSO

The 'clut' resource is described on The Color Table Resource .

DisposeCTable

Use the DisposeCTable procedure to dispose of a ColorTable record. The DisposeCTable procedure is also available as the DisposCTable procedure.

PROCEDURE DisposeCTable (cTable: CTabHandle);
cTable
A handle to a ColorTable record.

DESCRIPTION

The DisposeCTable procedure disposes of the ColorTable record whose handle you pass in the cTable parameter.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next